home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug167 / c_window.doc < prev    next >
Text File  |  1986-11-14  |  30KB  |  1,124 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.                 C_WINDOW
  19.                 --------
  20.  
  21.           Windowing for the IBM PC with the C Language
  22.                   Version 1.00
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.                                  C_WINDOW
  70.    ----------------------------------------------------------------------
  71.  
  72.  
  73.     INTRODUCTION
  74.  
  75.     C_WINDOW is a collection of functions that give windowing capa-
  76.     bility to the C programmer using an IBM PC or true compatible.    
  77.     C_WINDOW is written entirely in MicroSoft (Lattice) C, Version
  78.     2.03. It was compiled using the small model for both code and
  79.     data and is distributed in .OBJ format, ready to be linked to
  80.     your C programs. The source code of C_WINDOW is available for
  81.     $15. See page 11 of this documentation for details.
  82.  
  83.     The core C_WINDOW files are:
  84.     
  85.          C_WINDOW.OBJ    - The compiled windowing code
  86.          C_WINDOW.DOC    - The documentation
  87.          C_WDEF.INC     - Include file for your C code
  88.          C_W-DEMO.EXE    - Windowing demonstration program
  89.  
  90.     To use the C_WINDOW functions in your Lattice C program:
  91.     
  92.      (1) Include the file C_WDEF.INC in your C source file. 
  93.          C_WDEF.INC defines the C_WINDOW functions and associated
  94.          constants and variables. If the C_WDEF.INC file is missing,
  95.          you can extract it from the sample program C_W-DEMO.C listed
  96.          at the end of this documentation.    
  97.  
  98.      (2) Compile your C source file using the small code and data
  99.          model.
  100.  
  101.      (3) Link C_WINDOW.OBJ to your code:
  102.  
  103.         LINK CS + yourprog + C_WINDOW, yourprog.EXE,, MCS.LIB
  104.  
  105.     To allow other C compilers to compile the C_WINDOW source code, 
  106.     standard C syntax is used where-ever possible. There are only
  107.     three non-standard C functions used: INT86(), PEEK() and POKE().
  108.     If your compiler doesn't include these functions, you will have 
  109.     to write your own. Lattice C compatible versions of the three
  110.     above functions, written in assembler, plus a full explanation, 
  111.     are on the source code disk. Also, if you don't have an IBM PC or
  112.     compatible, and you are familiar with reading and writing to the
  113.     video RAM of your computer, you can adapt C_WINDOW for use on
  114.     your PC.
  115.  
  116.     Near the end of this documentation is the C source of a sample
  117.     windowing program. It has been compiled as C_W-DEMO.EXE and is
  118.     part of the C_WINDOW package. If C_W-DEMO.EXE is missing, you can
  119.     extract the source of C_W-DEMO.C from this documentation and
  120.     compile it to see a demonstration of C_WINDOW.    
  121.  
  122.     An array of bytes, called the window buffer, is used to store
  123.     each defined window, plus the section of the screen that each
  124.     window overlays.  The window buffer size has been defined in the
  125.     C_WINDOW code to be 10000 bytes.  This is a compromise value.
  126.     Larger allows more active window definitions, smaller means a
  127.  
  128.  
  129.                                     1
  130.  
  131.  
  132.  
  133.  
  134.  
  135.                                  C_WINDOW
  136.    ----------------------------------------------------------------------
  137.  
  138.  
  139.     smaller program.  When a window is defined, storage is allocated
  140.     in the window buffer.  The standard IBM PC screen, in 80 column 
  141.     alphanumeric mode, uses 4000 bytes (80 x 25 x 2) of video RAM.
  142.     Each character on the screen has a trailing attribute byte that 
  143.     indicates if the character is bright or dark, blinking, etc.
  144.     10000 bytes is enough to create a window the size of the screen 
  145.     (4000 bytes to save old screen, 4000 for window), plus another
  146.     little window. Or several medium sized windows. 
  147.  
  148.     C_WINDOW allows deallocation of window storage so you can have as
  149.     many windows as you like by deallocating and redefining them as 
  150.     needed. The only restriction is that only as many windows as can
  151.     be defined in the window buffer can be visible at any one time. 
  152.  
  153.     The main reason why the window buffer's size is explicitly
  154.     defined in the code, rather than using dynamic memory allocation
  155.     is that if the program can load on a particular computer with x 
  156.     amount of memory, then it will run on that computer. The program
  157.     is self-contained.
  158.  
  159.  
  160.     OVERVIEW OF FUNCTIONS
  161.  
  162.     YOU MUST ALWAYS CALL W_INIT() BEFORE USING ANY OF C_WINDOW's
  163.     FUNCTIONS. Do NOT neglect to do this, as several important data 
  164.     pointers are initialized.
  165.  
  166.     There are two kinds of functions available: those that are
  167.     specific to the C_WINDOW environment, and those that are comple-
  168.     mentary. The functions specific to C_WINDOW are preceded by "W_".  
  169.  
  170.     The four major windowing functions are:
  171.  
  172.         (1) Defining a window with W_DEF().
  173.         (2) Opening a window with W_OPEN().
  174.         (3) Closing the most recently opened window with W_CLOSE().
  175.         (4) Deallocating window(s) and releasing window buffer
  176.             space with W_KILL().
  177.  
  178.     The flag "err_exit" controls the action taken when a windowing 
  179.     error occurs. "err_exit" is declared as EXTERNal CHAR in 
  180.     C_WDEF.INC. If you set "err_exit" to TRUE (default), the program 
  181.     will return to the operating system after an error message window
  182.     is displayed.  The name of the windowing function and what is
  183.     wrong with what you are asking the function to do will be
  184.     indicated in the error message window.    
  185.  
  186.     If you set "err_exit" FALSE, for all C_WINDOW functions that 
  187.     return a status code (1 == OK, 0 == error), be sure to check that
  188.     no error has occurred. If a windowing function returns an error 
  189.     code, do not ignore it.  Terminate the program and check your
  190.     code for the cause of the error. Often the problem is as simple 
  191.     as mixing the X and Y coordinates up, or not specifying enough
  192.     arguments when a function is called.
  193.  
  194.  
  195.                                     2
  196.  
  197.  
  198.  
  199.  
  200.  
  201.                                  C_WINDOW
  202.    ----------------------------------------------------------------------
  203.  
  204.  
  205.  
  206.     A window's width and height is specified when it is defined.  When
  207.     it is opened, it can be located at any location on the screen, as
  208.     long as it doesn't stray outside of the screen's boundaries. If 
  209.     you have specified a border for a window, the writeable area of 
  210.     the window is reduced to fit inside the border. THE UPPER LEFT
  211.     CORNER OF THE WRITEABLE AREA OF A WINDOW IS AT HORIZONTAL (X)
  212.     COORDINATE 0 AND VERTICAL (Y) COORDINATE 0. IF NO WINDOWS ARE
  213.     OPEN, WINDOWING COMMANDS ARE RELATIVE TO THE STANDARD 80 x 25
  214.     SCREEN. 
  215.  
  216.     No more than one version of a defined window can be open at any 
  217.     one time, irregardless of screen placement. This is because each
  218.     window's storage contains information about the section of screen
  219.     it overlaid and opening a second version of the same window would
  220.     overwrite that information.
  221.  
  222.     W_WRITE() is the C_WINDOW screen writing function. It does not
  223.     attempt to interpret and act on any characters, including carriage
  224.     returns and line feeds. The only action taken is to wrap-around on
  225.     the active window if the cursor is at the right side of the window
  226.     and to scroll up if the bottom of the window is reached. Any extra
  227.     text handling will have to be added by you. The advantage is that
  228.     you can write any character to a window with W_WRITE(). 
  229.  
  230.     W_GETSTR() is the C_WINDOW screen string input function. You can
  231.     specify the maximum length of an input string so that no borders
  232.     are over-written. Character editing capabilities are included.    
  233.     The standard C function SSCANF() can be used to perform formatted
  234.     input conversion on the string read by W_GETSTR().
  235.  
  236.     Any standard C input/output functions that involve outputting
  237.     carriage returns or line feeds to the screen MUST be avoided when
  238.     a window is open. The standard C input/output functions know
  239.     nothing about the windowing environment and can easily write
  240.     across a window's border. Functions like PRINTF() can be used
  241.     with care, providing the user (1) first positions the cursor in a
  242.     window with W_GOTOXY() (2) never sends a carriage return or line
  243.     feed to the screen and (3) avoids writing across a window's
  244.     border. 
  245.  
  246.     All function calls must include all parameters, even if they are
  247.     only dummy place-holders. For example, if a window has been
  248.     defined without a border, the window opening function W_OPEN()
  249.     must include all 5 parameters, even though the border type
  250.     specification is ignored.
  251.  
  252.     C_WINDOW automatically selects 80 column alphanumeric mode
  253.     whether you have a monochrome or graphics screen. The windowing 
  254.     functions W_WRITE(), W_GETSTR(), and W_DSP1() expect character
  255.     attributes. Attribute definitions, controlling character color, 
  256.     intensity, etc, are contained in W_DEF.INC. You combine them by 
  257.     ORing definitions together. For example, FG_BLUE | BG_RED yields
  258.     blue characters on a red background. To select standard white-on-
  259.  
  260.  
  261.                                     3
  262.  
  263.  
  264.  
  265.  
  266.  
  267.                                  C_WINDOW
  268.    ----------------------------------------------------------------------
  269.  
  270.  
  271.     black for either a monochrome or color screen, specify 7 as the 
  272.     character attribute.
  273.  
  274.  
  275.     FUNCTIONS CONTAINED IN C_WINDOW
  276.  
  277.       W_INIT - Initialize windowing
  278.  
  279.     Useage: 
  280.  
  281.       w_init();
  282.  
  283.     W_INIT() sets up pointers to the window buffer, detects the type
  284.     of monitor (color or monochrome), selects 80 column alphanumeric
  285.     mode, sets the display page to zero, and sets up initial window 
  286.     dimensions to 80 x 25. If your computer is not an IBM PC or
  287.     compatible, W_INIT will detect this and abort the program.
  288.  
  289.     YOU MUST CALL W_INIT() BEFORE CALLING ANY OTHER C_WINDOW
  290.     FUNCTIONS. Failure to do this can cause random sections of memory
  291.     to be overwritten.
  292.  
  293.  
  294.       W_DEF - Define a window
  295.  
  296.     Useage: 
  297.  
  298.       wnum = w_def (wid, hgt, border);
  299.         int  wnum;    /* 0 if error, window access number otherwise */
  300.         int  wid;  /* Width of window, including optional border  */
  301.         int  hgt;  /* Height of window, including optional border */
  302.         char border;  /* TRUE (1) if border, FALSE (0) if no border */
  303.  
  304.     Example:
  305.  
  306.         if ((w1 = w_def(x1, y1, TRUE)) == 0)
  307.             /* w_def error handler here */
  308.         /* otherwise continue */
  309.  
  310.     Define a window and reserve storage for it in the window buffer.
  311.     A window must be defined before it is opened.
  312.  
  313.     The width and height parameters include the window border, if a 
  314.     border is specified. If the window has a border, then the
  315.     writeable area of the window is reduced to fit inside the border.
  316.     For example, a bordered window that has a width of 30 and a height
  317.     of 10 has writeable coordinates of 0..27 in the horizontal (X)
  318.     direction and 0..7 in the vertical (Y) direction.  If the window
  319.     didn't have a border, the X and Y ranges would be 0..29 and 0..9
  320.     respectively.
  321.  
  322.     You cannot define a window larger than the standard screen. Also,
  323.     the window must not be smaller than three columns by three rows 
  324.     if a border is specified and one row by one column if no border 
  325.  
  326.  
  327.                                     4
  328.  
  329.  
  330.  
  331.  
  332.  
  333.                                  C_WINDOW
  334.    ----------------------------------------------------------------------
  335.  
  336.  
  337.     is specified. In other words, at least one writeable character
  338.     position must be on the window. 
  339.  
  340.     Be sure to check the return code for 0, the error condition.
  341.     Errors occur if the window is too small, too big, or if there is
  342.     not enough room for the window in the window buffer.
  343.  
  344.  
  345.       W_OPEN - Open a pre-defined window
  346.  
  347.     Useage:
  348.  
  349.       status = w_open (wnum, x, y, bdr_type, clear);
  350.         int  status;  /* 1 if sucess, 0 if error */
  351.         int  wnum;    /* Value returned by a previous W_DEF() */
  352.         int  x;  /* Horizontal coordinate of upper left corner */
  353.         int  y;  /* Vertical coordinate of upper left corner */
  354.         char bdr_type;  /* Border type (if specified by W_DEF()) */
  355.         char clear;  /* TRUE means pre-clear window, FALSE means
  356.                 retain previous contents */
  357.  
  358.     Open a window that has been previously defined by a call to
  359.     W_DEF(). If a window is being opened for the first time, then the
  360.     contents of the window are initialized to spaces. If the window 
  361.     is being opened after having been previously open, the previous 
  362.     contents of the window will be re-displayed, unless "clear" is 
  363.     set to TRUE. The include file W_DEF.INC defines the six border
  364.     types.
  365.  
  366.     "x" and "y" are absolute locations on the standard 80 x 25 screen 
  367.     and specify the location of the upper left corner of the window 
  368.     to be opened.
  369.  
  370.     Be sure to check the return code for 0, the error condition.
  371.     Errors occur if wnum is to small or big, if the window is already
  372.     open, or if the window won't fit on the screen at the absolute
  373.     X,Y location specified. 
  374.  
  375.  
  376.       W_CLOSE - Close a window
  377.  
  378.     Useage: 
  379.  
  380.       w_close();
  381.  
  382.     Close the most recently opened window and restore the previously
  383.     overwritten section of screen.    
  384.  
  385.     If you attempt to close the standard screen, W_CLOSE() will
  386.     simply return, so extra W_CLOSE() calls are ignored.
  387.  
  388.     There is no error return code.    
  389.  
  390.  
  391.  
  392.  
  393.                                     5
  394.  
  395.  
  396.  
  397.  
  398.  
  399.                                  C_WINDOW
  400.    ----------------------------------------------------------------------
  401.  
  402.  
  403.       W_KILL - Deallocate window(s)
  404.  
  405.     Useage:
  406.  
  407.       status = w_kill (wnum);
  408.         int  status;  /* 1 if sucess, 0 if error */
  409.         int  wnum;    /* Number of window to kill */
  410.  
  411.     Deallocate window, and all subsequently defined windows. For
  412.     example:
  413.  
  414.         if ((w1 = w_def(x1, y1, FALSE)) == 0)
  415.             /* Error handler here */
  416.         if ((w2 = w_def(x2, y2, TRUE)) == 0)
  417.             /* Error handler here */
  418.         if ((w3 = w_def(x3, y3, TRUE)) == 0)
  419.             /* Error handler here */
  420.         /* De-allocate w2. Also de-allocate w3, because */
  421.         /* it was defined after w2, but not w1, because */
  422.         /* it was defined before w2 */
  423.         if ((status = w_kill(w2)) == 0)
  424.             /* w_kill error handler here */
  425.  
  426.     When W_KILL() is called, all of the open windows on the screen
  427.     are automatically closed. This is done because the deallocated
  428.     window(s) may be partially or fully under a window that is not
  429.     being deallocated.
  430.  
  431.     Be sure to check the return code for 0, the error condition.
  432.     Errors occur if wnum is too small or too big or if no window is 
  433.     associated with wnum.
  434.  
  435.  
  436.       W_SCROLL - Scroll contents of window
  437.  
  438.     Useage:
  439.  
  440.       w_scroll (dir, num);
  441.         int  dir;  /* Direction of scroll; 0 == up, 1 == down */
  442.         int  num;  /* Number of lines to scroll */
  443.  
  444.     The current window is scrolled in "dir" direction for "num" 
  445.     lines.
  446.  
  447.  
  448.       W_WRITE - Write a string to a window
  449.  
  450.     Useage:
  451.  
  452.       w_write (s, attrib);
  453.         char  *s;  /* Pointer to string */
  454.         char  attrib;  /* String display attribute */
  455.  
  456.     Display NULL terminated string in current window at location set
  457.  
  458.  
  459.                                     6
  460.  
  461.  
  462.  
  463.  
  464.  
  465.                                  C_WINDOW
  466.    ----------------------------------------------------------------------
  467.  
  468.  
  469.     by W_GOTOXY(). If the right hand side of the window is reached, 
  470.     the cursor will wrap-around to the next line. If the cursor
  471.     reaches the bottom of the current window, the contents of the
  472.     window will scroll up 1 line.
  473.  
  474.     No control characters are recognized, so any character can be
  475.     displayed.
  476.  
  477.     See C_WDEF.INC for the pre-defined display attribute values.
  478.  
  479.  
  480.       W_GETSTR - Read string
  481.  
  482.     Useage:
  483.  
  484.       w_getstr (s, maxc, attrib);
  485.         char *s;  /* Pointer to input buffer */
  486.         int  maxc;    /* Max char count */
  487.         char attrib;  /* attribute of characters entered */
  488.  
  489.     Read a string from the keyboard. Always position the cursor with
  490.     W_GOTOXY() before calling W_GETSTR(). "maxc" is the maximum 
  491.     number of characters allowed. The cursor will not move beyond the
  492.     limit specified by "maxc". For example, if "maxc" == 10, then 
  493.     only 10 characters can be entered. This is useful for avoiding
  494.     over-writing a window's borders.
  495.  
  496.     You can edit the input string:
  497.         (1) Pressing <RETURN> as the first keystroke leaves the
  498.             input buffer unaltered.
  499.         (2) If the first keystroke is a printable character, the
  500.             rest of the input buffer will be cleared.
  501.         (3) The back-space key deletes one character to the left
  502.             of the cursor.
  503.         (4) The DEL key deletes the character above the cursor.
  504.         (5) The left and right arrow keys move the cursor along 
  505.             the input buffer string.
  506.         (6) Pressing <RETURN> ends the editing.
  507.  
  508.     The input buffer must be at least 1 byte longer than "maxc", to 
  509.     make room for the trailing '\0', which is always appended.
  510.  
  511.     See C_WDEF.INC for the pre-defined display attribute values.
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                     7
  526.  
  527.  
  528.  
  529.  
  530.  
  531.                                  C_WINDOW
  532.    ----------------------------------------------------------------------
  533.  
  534.  
  535.       W_DSP1 - Display 1 character
  536.  
  537.     Useage:
  538.  
  539.       status = w_dsp1 (x, y, ch, attrib)
  540.         int  status;  /* 1 if OK, 0 if error */
  541.         int  x;  /* X position */
  542.         int  y;  /* Y position */
  543.         char ch;  /* character */
  544.         char attrib;  /* attribute */
  545.  
  546.     Display a single character at an X, Y location relative to the
  547.     currently open window.    
  548.  
  549.     If no windows are open, the X and Y coordinates correspond to
  550.     absolute locations on the standard 80 x 25 screen. The upper left
  551.     coordinate is (0, 0).
  552.  
  553.     See C_WDEF.INC for the pre-defined display attribute values.
  554.  
  555.     Be sure to check the return code for 0, the error condition. An 
  556.     error occurs if the X,Y position is outside of the currently
  557.     active window.    
  558.  
  559.  
  560.       W_GETCY - Get vertical (Y) position of cursor
  561.  
  562.     Useage:
  563.  
  564.       i = w_getcy();
  565.         int  i;  /* Y position */
  566.  
  567.  
  568.     This function returns the current Y position of the cursor,
  569.     relative to the upper left corner (0, 0) of the writeable part of
  570.     the current window. If no windows are open, the Y position is
  571.     relative to the upper left corner of the standard screen.
  572.  
  573.  
  574.       W_GETCX - Get horizontal (X) position of cursor
  575.  
  576.     Useage:
  577.  
  578.       i = w_getcx();
  579.         int  i;  /* X position */
  580.  
  581.     This function returns the current X position of the cursor,
  582.     relative to the upper left corner (0, 0) of the writeable part of
  583.     the current window. If no windows are open, the X position is
  584.     relative to the upper left corner of the standard screen.
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                     8
  592.  
  593.  
  594.  
  595.  
  596.  
  597.                                  C_WINDOW
  598.    ----------------------------------------------------------------------
  599.  
  600.  
  601.       W_GOTOXY - Move cursor
  602.  
  603.     Useage:
  604.  
  605.       status = w_gotoxy (x, y);
  606.         int  status;  /* 1 if OK, 0 if error */
  607.         int  x;  /* Horizontal position */
  608.         int  y;  /* Vertical position */
  609.  
  610.     Go to specified X, Y location on the writeable part of the
  611.     current window. If you specified a border when you defined and
  612.     opened the window, the writeable part of the window is reduced to
  613.     fit inside the border. For example, if you specified a window
  614.     that was 10 x 10, and it had a border, then the horizontal (X)
  615.     and vertical (Y) coordinates for W_GOTOXY() can vary between
  616.     0..7.
  617.  
  618.     If there are no windows open, the coordinates refer to the
  619.     standard 80 x 25 screen.
  620.  
  621.     Be sure to check the return code for 0, the error condition. An 
  622.     error occurs if the X,Y position is outside of the currently
  623.     active window.
  624.  
  625.  
  626.     COMPLEMENTARY FUNCTIONS
  627.  
  628.       The following functions are not part of the C_WINDOW environment. 
  629.       They are included because they provide useful windowing support.    
  630.  
  631.  
  632.       BORDER - Draw border on screen
  633.  
  634.     Useage:
  635.  
  636.       status = border (x, y, wid, hgt, type);
  637.         int  status;  /* 1 if sucess, 0 if error */
  638.         int  x;  /* Upper left horizontal position */
  639.         int  y;  /* Upper left vertical position */
  640.         int  wid;  /* Width of border */
  641.         int  hgt;  /* Height of border */
  642.         char type;    /* Type of border */
  643.  
  644.     Draw a border around an area of the screen. X and Y are absolute
  645.     coordinates, relative to the standard 80 x 25 screen. The upper 
  646.     leftmost coordinate of the standard screen is (0, 0) and the lower
  647.     right coordinate of the standard screen is (79, 24).
  648.  
  649.     There are six types of borders:
  650.         (a) type = 0;  /* Border outline is spaces */
  651.         (b) type = 1;  /* Single line border,
  652.                   Horizontal and vertical */
  653.         (c) type = 2;  /* Double line border,
  654.                   Horizontal and vertical */
  655.  
  656.  
  657.                                     9
  658.  
  659.  
  660.  
  661.  
  662.  
  663.                                  C_WINDOW
  664.    ----------------------------------------------------------------------
  665.  
  666.  
  667.         (d) type = 3;  /* Double horizontal lines,
  668.                   Single vertical lines */
  669.         (e) type = 4;  /* Single horizontal lines,
  670.                   Double vertical lines */
  671.         (f) type = 5;  /* Solid block horizontal and vertical */
  672.  
  673.     The include file C_WDEF.INC defines the border types listed above.
  674.  
  675.     Be sure to check the return code for 0, the error condition. An 
  676.     error occurs if the border type is not one of the types specified
  677.     or if the border will not fit on the standard 80 x 25 screen.
  678.  
  679.  
  680.       KEYIN - Read a keyboard character
  681.  
  682.     Useage:
  683.  
  684.       c = keyin();
  685.         char  c;  /* Character returned */
  686.  
  687.     Read the next character entered at the keyboard. The character is
  688.     not echoed to the screen. C_WDEF.INC declares a variable "extend" 
  689.     as EXTERNal CHAR. If the character location "extend" is set to 
  690.     TRUE (1) when KEYIN() returns, then the value returned by KEYIN()
  691.     is the extended character code. Otherwise, the character is a
  692.     regular ASCII character. For example:
  693.  
  694.         c = keyin();
  695.         if (extend)
  696.             /* process function keys, etc */
  697.         else
  698.             /* standard character */
  699.  
  700.  
  701.       BEEP - Sound speaker
  702.  
  703.     Useage:
  704.  
  705.     beep(count)
  706.       int  count;  /* Duration */
  707.  
  708.     Beep the speaker. A value of 500 for "count" gives a short chirp. 
  709.     "count" is an integer value, so it must not exceed 32,767.
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                        10
  724.  
  725.  
  726.  
  727.  
  728.  
  729.                                  C_WINDOW
  730.    ----------------------------------------------------------------------
  731.  
  732.  
  733.     GETTING THE C SOURCE
  734.  
  735.     There are two places to get the C_WINDOW source code:
  736.  
  737.          In the USA for $15:      In Europe for 12 English pounds:
  738.  
  739.          Christopher McVicar         John Poole
  740.          c/o IMAGE                 c/o IMAGE
  741.          124 Wellington Heights         27 Cobham Road
  742.          Avon, Connecticut    06001         Ferndown Industrial Est.
  743.                          Wimborne, Dorset, England
  744.  
  745.     The source code will be sent the same day we receive payment. It
  746.     will be on a DOS 1.1 formatted single sided floppy diskette for 
  747.     compatibility with all versions of PC-DOS and MS-DOS.
  748.  
  749.     Also on the diskette are:
  750.         (1) A text file explaining what the Lattice C functions 
  751.             PEEK(), POKE(), and INT86() do.
  752.         (2) Lattice C compatible 8086 assembler sources for
  753.             PEEK(), POKE(), and INT86().
  754.  
  755.  
  756.     DISCLAIMER
  757.  
  758.     Users of C_WINDOW do so at their own risk. No representations as
  759.     to the program's suitability for any purpose are made. Users of 
  760.     C_WINDOW are entirely responsible for loss or damage of any kind
  761.     caused by C_WINDOW.
  762.  
  763.  
  764.     RESTRICTIONS
  765.  
  766.     Non-commercial users of C_WINDOW may use C_WINDOW without any
  767.     restrictions.
  768.  
  769.     Commercial users of C_WINDOW, i.e. individuals or companies using
  770.     or planning to use C_WINDOW as part of a saleable product, must 
  771.     contact one of us and get written permission to include part or 
  772.     all of C_WINDOW in their product.  This is only a formality to
  773.     keep a company or individual from selling an essentially
  774.     unmodified version of C_WINDOW as their own product.
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.                                        11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.                                  C_WINDOW
  796.    ----------------------------------------------------------------------
  797.  
  798.  
  799.     DEMONSTRATION PROGRAM
  800.  
  801.     /* C_W-DEMO.C
  802.  
  803.         C_WINDOW Version 1.0 demonstration program contained
  804.         in C_WINDOW.DOC and compiled as C_W-DEMO.EXE
  805.  
  806.     */
  807.  
  808.     /***********************************************/
  809.     /* Use your text editor to place the following */
  810.     /* defines and declarations in an include file */
  811.     /* called C_WDEF.INC if C_WDEF.INC is missing. */
  812.     /* MAKE SURE ALL #DEFINES ARE IN COLUMN 1!!    */
  813.     /***********************************************/
  814.     /* C_WDEF.INC - Include file for C_WINDOW Vers 1.0 */
  815.  
  816.  
  817.     #define FALSE    0
  818.     #define TRUE    1
  819.  
  820.     /* Window border types sent to w_open() */
  821.     #define SPACES    0    /* blanks */
  822.     #define SNGL_LN 1    /* single lines */
  823.     #define DBL_LN    2    /* double lines */
  824.     #define MXD_1    3    /* double horiz, single vert */
  825.     #define MXD_2    4    /* double vert, single horiz */
  826.     #define BLK_LN    5    /* block characters */
  827.  
  828.     /* Monochrome defines */
  829.     #define NORM    0x07    /* std. white on black */
  830.     #define REVERS    0x70    /* reverse video */
  831.     /* Character display attributes, to be */
  832.     /* added or ORed to the above base modes */
  833.     #define BRIGHT    0x08
  834.     #define BLINK    0x80
  835.  
  836.     /* Color screen foreground defines */
  837.     #define FG_BLACK    0x00
  838.     #define FG_BLUE     0x01
  839.     #define FG_GREEN    0x02
  840.     #define FG_CYAN     0x03
  841.     #define FG_RED        0x04
  842.     #define FG_MAGENTA    0x05
  843.     #define FG_BROWN    0x06
  844.     #define FG_WHITE    0x07
  845.     #define FG_GRAY     0x08
  846.     #define FG_LTBLUE    0x09    /* light blue */
  847.     #define FG_LTGREEN    0x0A    /* light green */
  848.     #define FG_LTCYAN    0x0B    /* light cyan */
  849.     #define FG_LTRED    0x0C    /* light red */
  850.     #define FG_LTMAGENTA    0x0D    /* light magenta */
  851.     #define FG_YELLOW    0x0E
  852.     #define FG_BRTWHITE    0x0F    /* bright white */
  853.  
  854.  
  855.                                        12
  856.  
  857.  
  858.  
  859.  
  860.  
  861.                                  C_WINDOW
  862.    ----------------------------------------------------------------------
  863.  
  864.  
  865.  
  866.     /* Color screen background defines to be ORed to */
  867.     /* the above foreground colors */
  868.     #define BG_BLACK    0x00
  869.     #define BG_BLUE     0x10
  870.     #define BG_GREEN    0x20
  871.     #define BG_CYAN     0x30
  872.     #define BG_RED        0x40
  873.     #define BG_MAGENTA    0x50
  874.     #define BG_BROWN    0x60
  875.     #define BG_WHITE    0x70
  876.     /* Color screen blink attribute to be ORed to the */
  877.     /* above foreground colors */
  878.     #define COLRBLINK    0x80
  879.  
  880.     /* Direction of window scroll */
  881.     #define UP    0
  882.     #define DOWN    1
  883.  
  884.     /* Border parameter sent to w_def () */
  885.     #define NOBORDER 0
  886.     #define BORDER    1
  887.  
  888.     /* Parameter sent to w_open () */
  889.     #define NOCLR    0    /* No window pre-clear */
  890.     #define CLR    1    /* Pre-clear window */
  891.  
  892.     /* Allow access to C_WINDOW functions */
  893.     extern    w_init ();
  894.     extern    w_def ();
  895.     extern    w_open ();
  896.     extern    w_close ();
  897.     extern    w_kill ();
  898.     extern    w_write ();
  899.     extern    w_dsp1 ();
  900.     extern    w_getstr ();
  901.     extern    w_scroll ();
  902.     extern    w_getcx ();
  903.     extern    w_getcy ();
  904.     extern    w_gotoxy ();
  905.  
  906.     /* Non-windowing specific */
  907.     extern    border ();
  908.     extern    keyin ();
  909.     extern    beep ();
  910.  
  911.     /* Flag altered by keyin () */
  912.     extern    char extend;
  913.  
  914.     /* Flag used in error handling */
  915.     extern    char err_exit;
  916.  
  917.     /***********************************************/
  918.  
  919.  
  920.  
  921.                                        13
  922.  
  923.  
  924.  
  925.  
  926.  
  927.                                  C_WINDOW
  928.    ----------------------------------------------------------------------
  929.  
  930.  
  931.  
  932.     main()
  933.  
  934.     {
  935.         int    w1, w2, w3, w4;
  936.         int    i, c;
  937.         char    str[10];
  938.         char    *strptr;
  939.  
  940.         /* always call this function first */
  941.         w_init ();
  942.  
  943.         strptr = str;
  944.  
  945.         w_gotoxy (30, 7);
  946.         w_write ("Windows for C", NORM|BRIGHT);
  947.         border (10, 5, 55, 7, BLK_LN);
  948.         w_gotoxy (21, 8);
  949.         w_write ("*C_WINDOW Demonstration Program*", NORM);
  950.         w_gotoxy (25, 9);
  951.         w_write ("(Source in C_WINDOW.DOC)", NORM);
  952.         w_gotoxy (17, 15);
  953.         w_write ("Send $15 for the source of C_WINDOW to:", NORM);
  954.         w_gotoxy (26, 18);
  955.         w_write ("Christopher McVicar", NORM|BRIGHT);
  956.         w_gotoxy (31, 19);
  957.         w_write ("c/o IMAGE", NORM|BRIGHT);
  958.         w_gotoxy (25, 20);
  959.         w_write ("124 Wellington Heights", NORM|BRIGHT);
  960.         w_gotoxy (28, 21);
  961.         w_write ("Avon, CT  06001", NORM|BRIGHT);
  962.         w_gotoxy (50, 23);
  963.         w_write ("Press any key to continue", NORM|BRIGHT);
  964.         keyin ();
  965.  
  966.         /* define 4 windows */
  967.         w1 = w_def (75, 5, BORDER);
  968.         w2 = w_def (60, 20, BORDER);
  969.         w3 = w_def (33, 14, BORDER);
  970.         w4 = w_def (44, 9, BORDER);
  971.  
  972.         w_open (w1, 0, 3, DBL_LN, CLR);
  973.         w_write ("Text can be ", NORM);
  974.         w_write ("blinking, ", NORM|BLINK);
  975.         w_write ("blinking bright, ", NORM|BRIGHT|BLINK);
  976.         w_write ("or just ", NORM|BRIGHT);
  977.         w_write ("bright. ", NORM|BRIGHT);
  978.         w_write ("All graphics card colors are also available. ",NORM);
  979.         w_write ("Press any key to continue", NORM);
  980.         keyin ();
  981.  
  982.         w_open (w2, 20, 2, DBL_LN, CLR);
  983.         w_write ("The window can scroll up or down...", NORM);
  984.         w_gotoxy (0, 1);
  985.  
  986.  
  987.                                        14
  988.  
  989.  
  990.  
  991.  
  992.  
  993.                                  C_WINDOW
  994.    ----------------------------------------------------------------------
  995.  
  996.  
  997.         w_write ("Press any key to continue", NORM);
  998.         keyin ();
  999.         for (i = 0; i < 100; i++) {
  1000.             w_write ("Scrolling ", NORM);
  1001.             w_write ("up ",NORM|BLINK);
  1002.             w_write ("in the window ", NORM|BRIGHT);
  1003.         }
  1004.         w_scroll (UP, 5);
  1005.         w_gotoxy (0, 17);
  1006.         w_write ("Press any key to continue", NORM);
  1007.         keyin ();
  1008.  
  1009.         w_open (w3, 10, 5, MXD_1, CLR);
  1010.         w_write ("Press any key to continue", NORM);
  1011.         keyin ();
  1012.  
  1013.         w_open (w4, 4, 10, BLK_LN, CLR);
  1014.         *(strptr+1) = 0; /* NULL terminated string */
  1015.         w_gotoxy (0, 1);
  1016.         w_write ("When a window is open, lines automatically", NORM);
  1017.         w_gotoxy (0, 2);
  1018.         w_write ("wrap around when the right edge is reached", NORM);
  1019.         w_gotoxy (0, 3);
  1020.         w_write ("Type in a line of characters or press", NORM);
  1021.         w_gotoxy (0, 4);
  1022.         w_write ("<Carriage Return>..", NORM);
  1023.         w_gotoxy (0, 5);
  1024.         w_write ("Press ", NORM);
  1025.         w_write ("FUNCTION KEY 1 ", NORM|BRIGHT);
  1026.         w_write ("to quit.", NORM);
  1027.         w_gotoxy (0, 6);
  1028.         while (1) {
  1029.             /* 59 is extended code for function key 1 */
  1030.             if (((*strptr = keyin ()) == 59) && extend)
  1031.                 break;
  1032.             /* carriage return */
  1033.             if (*strptr == 0x0D) {
  1034.                 w_scroll (UP, 1);
  1035.                 i = w_getcy ();
  1036.                 w_gotoxy (0, i);
  1037.             }
  1038.             else
  1039.                 w_write (strptr, NORM);
  1040.         }
  1041.         w_close ();
  1042.  
  1043.         strptr = "12345";
  1044.         w_gotoxy (0, 0);
  1045.         w_write ("Strings can be edited using the", NORM);
  1046.         w_gotoxy (0, 1);
  1047.         w_write ("usual editing keys. Try editing", NORM);
  1048.         w_gotoxy (0, 2);
  1049.         w_write ("the following five character", NORM);
  1050.         w_gotoxy (0, 3);
  1051.  
  1052.  
  1053.                                        15
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.                                  C_WINDOW
  1060.    ----------------------------------------------------------------------
  1061.  
  1062.  
  1063.         w_write ("string:", NORM);
  1064.         w_gotoxy (0, 4);
  1065.         w_write ("<Carriage Return> to continue..", NORM);
  1066.         w_gotoxy (8, 3);
  1067.         w_getstr (strptr, 5, NORM|BRIGHT);
  1068.         w_close ();
  1069.  
  1070.         keyin ();
  1071.         w_close ();
  1072.  
  1073.         /* reopen prev window */
  1074.         w_open (w2, 0, 3, BLK_LN, NOCLR);
  1075.         w_gotoxy (0, 16);
  1076.         w_write ("Windows can be re-opened at a different location..",
  1077.             NORM);
  1078.         w_gotoxy (0, 17);
  1079.         w_write ("Press any key to continue", NORM);
  1080.  
  1081.         keyin ();
  1082.         w_close ();
  1083.  
  1084.         keyin ();
  1085.         w_close ();
  1086.     }
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                        16
  1120.  
  1121.  
  1122.  
  1123. 
  1124.